package net.entelijan.cobean.examples.showcase.config.toggle;

import net.entelijan.cobean.examples.showcase.ShowcaseTestFrame;
import net.entelijan.cobean.examples.showcase.config.toggle.ConfigBookTogglePanel;
import net.entelijan.cobean.examples.showcase.config.toggle.ConfigBookToggleShowcase;
import net.entelijan.testutil.CobeanTestUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.fest.swing.fixture.FrameFixture;
import org.fest.swing.fixture.JCheckBoxFixture;
import org.junit.Assert;
import org.junit.Test;

public class ToggleFestTestCase {

	@SuppressWarnings("unused")
	private static Log log = LogFactory.getLog(ToggleFestTestCase.class);

	@Test
	public void testAll() {
		ConfigBookTogglePanel panel = new ConfigBookTogglePanel();
		CobeanTestUtil.setComponentNamesFromPropertyNames(panel);
		ShowcaseTestFrame frame = new ShowcaseTestFrame(panel);
		FrameFixture frameFix = new FrameFixture(frame);
		try {
			frameFix.show();
			ConfigBookToggleShowcase sc = new ConfigBookToggleShowcase();
			JCheckBoxFixture translCheckBox = frameFix.checkBox("translationCheckBox");
			sc.init(panel);
			pause(100);
			translCheckBox.requireEnabled();
			
			translCheckBox.uncheck();
			pause(100);
			Assert.assertEquals(false, sc.getBook().getTranslation().booleanValue());
			
			sc.getBook().setTranslation(true);
			pause(100);
			translCheckBox.requireEnabled();
			
		} finally {
			frameFix.cleanUp();
		}

	}


	private synchronized void pause(int timeMs) {
		try {
			wait(timeMs);
		} catch (InterruptedException e) {
			// Do not mind
		}

	}

}
